package com.dingreading.cloud.app.service.impl;

import com.dingreading.cloud.app.entity.MemberActionLog;
import com.dingreading.cloud.app.entity.table.MemberActionLogTableDef;
import com.dingreading.cloud.app.mapper.MemberActionLogMapper;
import com.dingreading.cloud.app.service.MemberActionLogService;
import com.dingreading.cloud.common.util.EnumType;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 服务层实现。
 *
 * @author Administrator
 * @since 2023-11-22
 */
@Service
public class MemberActionLogServiceImpl extends BaseServiceImpl<MemberActionLogMapper, MemberActionLog, MemberActionLogTableDef> implements MemberActionLogService {

    @Override
    protected MemberActionLogTableDef getTable() {
        return MemberActionLogTableDef.memberActionLog;
    }


    @Override
    public List<MemberActionLog> getMemberBookActionLogGroupBookId(Long storeId, Long memberId, String time) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.storeId.eq(storeId))
                .and(table.memberId.eq(memberId))
                .and(table.actionType.eq(EnumType.ActionType.READ_BOOK.getType()))
                .and(table.addTime.likeLeft(time));

        QueryWrapper wrapper = QueryWrapper.create()
                .where(condition)
                .groupBy(table.storeBookId)
                .orderBy(table.id.asc());

        return getMapper().selectListByQuery(wrapper);
    }

}
